<?php
/**
 * Created by PhpStorm.
 * User: xiaoxin
 * Date: 2018/10/17 0017
 * Time: 9:51
 */
header("Content-type: image/png");
//创建画布
$width = 300;
$height = 100;
$src = imageCreateTrueColor($width,$height);
//设置颜色
$color = imageColorAllocate($src,255,255,255);
imageFill($src,0,0,$color);
$color = imageColorAllocate($src,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));
//设置实心矩形
//imagefilledrectangle ( $src, 100 , 0 , 200 , 100, $color);
//设置空心圆形
//imageellipse ( $src, 250 , 150 , 100 , 100 ,  $color );
//设置实心圆形
//imagefilledellipse  ( $src, 250 , 150 , 100 , 100 ,  $color );
//设置线条
for ($i=0;$i<5000; $i++){
	imagesetpixel ( $src , mt_rand(0,400) ,mt_rand(0,200) ,  $color );
}
//imageline ( $src, 50 , 100, 50 , 100,  $color );
//设置单一像素
//imagesetpixel ( $src , 250 , 150 ,  $color );
$str = 'qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM123456789';
$num = 4;
for ($i=0; $i <$num ; $i++) {
	$color = imageColorAllocate($src,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));
	$text = $str[mt_rand(0,strlen($str)-1)];
	$fontsize = 60;
	$y = ($height+$fontsize)/2;
	$diff = ($width/$num)-$fontsize > 0 ? ($width/$num)-$fontsize : 0;
	$x = ($width/$num)*$i+($diff)/2;
	imagettftext ($src, $fontsize , mt_rand(-30,30), $x , $y ,$color , 'Alpha Thin.ttf' , $text);
}
imagepng($src);